package com.yunhui.wx.controller;
import com.yunhui.wx.bean.response.TextRespMessage;
import com.yunhui.wx.service.CoreService;
import com.yunhui.wx.util.MessageUtils;
import com.yunhui.wx.util.SignUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author: Yun
 * @Description:
 * @Date: Created in 2017-11-28 11:07
 */
@Controller
public class CoreController {

    @Autowired
    CoreService coreService;

    /**
     * 确认请求来自微信服务器
     * @param signature 微信加密签名
     * @param timestamp 时间戳
     * @param nonce 随机数
     * @param echostr 随机字符串
     */
    @ResponseBody
    @GetMapping("/")
    public String doGet(String signature,String timestamp,String nonce,String echostr){
        if(SignUtil.checkSignature(signature,timestamp,nonce)){
            return echostr;
        }
        return null;
    }

    @ResponseBody
    @PostMapping("/")
    public String doPost(HttpServletRequest request){
        return coreService.process(request);
    }
}
